package cn.sx213.mongodb.repository;

import cn.sx213.mongodb.entity.Employee;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author liliang
 * @Description:
 * @Date 18/1/4 下午4:28
 */
@Component
public interface EmployeeRepository extends MongoRepository<Employee, String> {

    /**
     * 根据名称查询Employee
     *
     * @param name
     * @return
     */
    @Query("{'name' : ?0}")
    Employee getEmployeeByName(String name);

    /**
     * 根据年龄查询Employee列表
     *
     * @param age
     * @return
     */
    @Query(value = "{'age' : ?0}", fields = "{'name' : 1, 'id' : 1, 'age' : 1}")
    List<Employee> getEmployeeByAge(int age);

    /**
     * 根据名称和年龄查询Employee
     * @param
     * @param age
     * @return
     */
    @Query("{'name' : ?0,'age' : ?1}")
    List<Employee> getEmployeeByNameAndAge(String name, int age);
}
